<?php
/**
 * Class that operate on table 'event_others'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2015-05-26 14:36
 */
class EventOthersMySqlDAO implements EventOthersDAO{

	/**
	 * Get Domain object by primry key
	 *
	 * @param String $id primary key
	 * @return EventOthersMySql 
	 */
	public function load($id){
		$sql = 'SELECT * FROM event_others WHERE id = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($id);
		return $this->getRow($sqlQuery);
	}

	/**
	 * Get all records from table
	 */
	public function queryAll(){
		$sql = 'SELECT * FROM event_others';
		$sqlQuery = new SqlQuery($sql);
		return $this->getList($sqlQuery);
	}
	
	/**
	 * Get all records from table ordered by field
	 *
	 * @param $orderColumn column name
	 */
	public function queryAllOrderBy($orderColumn){
		$sql = 'SELECT * FROM event_others ORDER BY '.$orderColumn;
		$sqlQuery = new SqlQuery($sql);
		return $this->getList($sqlQuery);
	}
	
	/**
 	 * Delete record from table
 	 * @param eventOther primary key
 	 */
	public function delete($id){
		$sql = 'DELETE FROM event_others WHERE id = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($id);
		return $this->executeUpdate($sqlQuery);
	}
	
	/**
 	 * Insert record to table
 	 *
 	 * @param EventOthersMySql eventOther
 	 */
	public function insert($eventOther){
		$sql = 'INSERT INTO event_others (event_id, heading, orgnized_by, venue, date_time, contact_person, email, phone, description, banner, logo, youtube_url, created_by, created_date, updated_by, updated_date, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
		$sqlQuery = new SqlQuery($sql);
		
		$sqlQuery->setNumber($eventOther->eventId);
		$sqlQuery->set($eventOther->heading);
		$sqlQuery->set($eventOther->orgnizedBy);
		$sqlQuery->set($eventOther->venue);
		$sqlQuery->set($eventOther->dateTime);
		$sqlQuery->setNumber($eventOther->contactPerson);
		$sqlQuery->set($eventOther->email);
		$sqlQuery->set($eventOther->phone);
		$sqlQuery->set($eventOther->description);
		$sqlQuery->set($eventOther->banner);
		$sqlQuery->set($eventOther->logo);
		$sqlQuery->set($eventOther->youtubeUrl);
		$sqlQuery->setNumber($eventOther->createdBy);
		$sqlQuery->set($eventOther->created_date);
		$sqlQuery->setNumber($eventOther->updatedBy);
		$sqlQuery->set($eventOther->updated_date);
		$sqlQuery->setNumber($eventOther->status);

		$id = $this->executeInsert($sqlQuery);	
		$eventOther->id = $id;
		return $id;
	}
	
	/**
 	 * Update record in table
 	 *
 	 * @param EventOthersMySql eventOther
 	 */
	public function update($eventOther){
		$sql = 'UPDATE event_others SET event_id = ?, heading = ?, orgnized_by = ?, venue = ?, date_time = ?, contact_person = ?, email = ?, phone = ?, description = ?, banner = ?, logo = ?, youtube_url = ?, created_by = ?, created_date = ?, updated_by = ?, updated_date = ?, status = ? WHERE id = ?';
		$sqlQuery = new SqlQuery($sql);
		
		$sqlQuery->setNumber($eventOther->eventId);
		$sqlQuery->set($eventOther->heading);
		$sqlQuery->set($eventOther->orgnizedBy);
		$sqlQuery->set($eventOther->venue);
		$sqlQuery->set($eventOther->dateTime);
		$sqlQuery->setNumber($eventOther->contactPerson);
		$sqlQuery->set($eventOther->email);
		$sqlQuery->set($eventOther->phone);
		$sqlQuery->set($eventOther->description);
		$sqlQuery->set($eventOther->banner);
		$sqlQuery->set($eventOther->logo);
		$sqlQuery->set($eventOther->youtubeUrl);
		$sqlQuery->setNumber($eventOther->createdBy);
		$sqlQuery->set($eventOther->created_date);
		$sqlQuery->setNumber($eventOther->updatedBy);
		$sqlQuery->set($eventOther->updated_date);
		$sqlQuery->setNumber($eventOther->status);

		$sqlQuery->setNumber($eventOther->id);
		return $this->executeUpdate($sqlQuery);
	}

	/**
 	 * Delete all rows
 	 */
	public function clean(){
		$sql = 'DELETE FROM event_others';
		$sqlQuery = new SqlQuery($sql);
		return $this->executeUpdate($sqlQuery);
	}

	public function queryByEventId($value){
		$sql = 'SELECT * FROM event_others WHERE event_id = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->getList($sqlQuery);
	}

	public function queryByHeading($value){
		$sql = 'SELECT * FROM event_others WHERE heading = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByOrgnizedBy($value){
		$sql = 'SELECT * FROM event_others WHERE orgnized_by = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByVenue($value){
		$sql = 'SELECT * FROM event_others WHERE venue = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByDateTime($value){
		$sql = 'SELECT * FROM event_others WHERE date_time = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByContactPerson($value){
		$sql = 'SELECT * FROM event_others WHERE contact_person = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->getList($sqlQuery);
	}

	public function queryByEmail($value){
		$sql = 'SELECT * FROM event_others WHERE email = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByPhone($value){
		$sql = 'SELECT * FROM event_others WHERE phone = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByDescription($value){
		$sql = 'SELECT * FROM event_others WHERE description = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByBanner($value){
		$sql = 'SELECT * FROM event_others WHERE banner = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByLogo($value){
		$sql = 'SELECT * FROM event_others WHERE logo = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByYoutubeUrl($value){
		$sql = 'SELECT * FROM event_others WHERE youtube_url = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByCreatedBy($value){
		$sql = 'SELECT * FROM event_others WHERE created_by = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->getList($sqlQuery);
	}

	public function queryByCreatedDate($value){
		$sql = 'SELECT * FROM event_others WHERE created_date = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByUpdatedBy($value){
		$sql = 'SELECT * FROM event_others WHERE updated_by = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->getList($sqlQuery);
	}

	public function queryByUpdatedDate($value){
		$sql = 'SELECT * FROM event_others WHERE updated_date = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function queryByStatus($value){
		$sql = 'SELECT * FROM event_others WHERE status = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->getList($sqlQuery);
	}


	public function deleteByEventId($value){
		$sql = 'DELETE FROM event_others WHERE event_id = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByHeading($value){
		$sql = 'DELETE FROM event_others WHERE heading = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByOrgnizedBy($value){
		$sql = 'DELETE FROM event_others WHERE orgnized_by = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByVenue($value){
		$sql = 'DELETE FROM event_others WHERE venue = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByDateTime($value){
		$sql = 'DELETE FROM event_others WHERE date_time = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByContactPerson($value){
		$sql = 'DELETE FROM event_others WHERE contact_person = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByEmail($value){
		$sql = 'DELETE FROM event_others WHERE email = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByPhone($value){
		$sql = 'DELETE FROM event_others WHERE phone = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByDescription($value){
		$sql = 'DELETE FROM event_others WHERE description = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByBanner($value){
		$sql = 'DELETE FROM event_others WHERE banner = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByLogo($value){
		$sql = 'DELETE FROM event_others WHERE logo = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByYoutubeUrl($value){
		$sql = 'DELETE FROM event_others WHERE youtube_url = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByCreatedBy($value){
		$sql = 'DELETE FROM event_others WHERE created_by = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByCreatedDate($value){
		$sql = 'DELETE FROM event_others WHERE created_date = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByUpdatedBy($value){
		$sql = 'DELETE FROM event_others WHERE updated_by = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByUpdatedDate($value){
		$sql = 'DELETE FROM event_others WHERE updated_date = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->executeUpdate($sqlQuery);
	}

	public function deleteByStatus($value){
		$sql = 'DELETE FROM event_others WHERE status = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($value);
		return $this->executeUpdate($sqlQuery);
	}


	
	/**
	 * Read row
	 *
	 * @return EventOthersMySql 
	 */
	protected function readRow($row){
		$eventOther = new EventOther();
		
		$eventOther->id = $row['id'];
		$eventOther->eventId = $row['event_id'];
		$eventOther->heading = $row['heading'];
		$eventOther->orgnizedBy = $row['orgnized_by'];
		$eventOther->venue = $row['venue'];
		$eventOther->dateTime = $row['date_time'];
		$eventOther->contactPerson = $row['contact_person'];
		$eventOther->email = $row['email'];
		$eventOther->phone = $row['phone'];
		$eventOther->description = $row['description'];
		$eventOther->banner = $row['banner'];
		$eventOther->logo = $row['logo'];
		$eventOther->youtubeUrl = $row['youtube_url'];
		$eventOther->createdBy = $row['created_by'];
		$eventOther->created_date = $row['created_date'];
		$eventOther->updatedBy = $row['updated_by'];
		$eventOther->updated_date = $row['updated_date'];
		$eventOther->status = $row['status'];

		return $eventOther;
	}
	
	protected function getList($sqlQuery){
		$tab = QueryExecutor::execute($sqlQuery);
		$ret = array();
		for($i=0;$i<count($tab);$i++){
			$ret[$i] = $this->readRow($tab[$i]);
		}
		return $ret;
	}
	
	/**
	 * Get row
	 *
	 * @return EventOthersMySql 
	 */
	protected function getRow($sqlQuery){
		$tab = QueryExecutor::execute($sqlQuery);
		if(count($tab)==0){
			return null;
		}
		return $this->readRow($tab[0]);		
	}
	
	/**
	 * Execute sql query
	 */
	protected function execute($sqlQuery){
		return QueryExecutor::execute($sqlQuery);
	}
	
		
	/**
	 * Execute sql query
	 */
	protected function executeUpdate($sqlQuery){
		return QueryExecutor::executeUpdate($sqlQuery);
	}

	/**
	 * Query for one row and one column
	 */
	protected function querySingleResult($sqlQuery){
		return QueryExecutor::queryForString($sqlQuery);
	}

	/**
	 * Insert row to table
	 */
	protected function executeInsert($sqlQuery){
		return QueryExecutor::executeInsert($sqlQuery);
	}
}
?>